package com.ithema.controller;

import com.ithema.entity.Article;
import com.ithema.entity.PageBean;
import com.ithema.entity.Result;
import com.ithema.service.ArticleService;
import com.ithema.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    ArticleService articleService;

    @PostMapping("/list")
    public Result<PageBean<Article>> list(Integer pageNum,
                                          Integer pageSize,
                                          @RequestParam(required = false)
                                          Integer categoryId,
                                          @RequestParam(required = false)
                                          String state) {
        return  Result.success(articleService.articleList(pageNum, pageSize, categoryId, state));
    }
    @PostMapping("/insert")
    public Result insert(@RequestBody @Validated Article article) {
        articleService.insert(article);
        return  Result.success("文章新增成功");
    }
}
